<?php
/**
 * 學習描述文字, 努力程度
 * @author cik
 *
 */
class Score_Model_Description extends Score_Model_Score
{


    /**
     *  取該科學期成績
     * @return unknown_type
     */
    public function getScores()
    {
      if ($this->_isElective) {
            $q = Doctrine_Query::create()
            ->select('s.student_sn')
            ->from('Student_Model_StudentScoreElectiveStudent s')
            ->leftJoin('s.Student_Model_StudentScoreElectiveGroup g')
            ->where('g.teacher_course_sn=?',$this->_teacherCourse->sn );
            foreach($q->fetchArray() as $row)
            $studentArr[] = $row['student_sn'];
        }
        $q = Doctrine_Query::create()
        ->select('a.*')
        ->from('Student_Model_StudentScoreSemester a')
        ->leftJoin('Student_Model_StudentSemester b')
        ->where('a.student_sn=b.student_sn')
        ->andwhere('a.subject_sn=?', $this->_teacherCourse->subject_sn)
        ->andwhere('b.year=?',  $this->_teacherCourse->year)
        ->andWhere('b.semester=?',  $this->_teacherCourse->semester)
        ->andWhere('b.grade=?',  $this->_teacherCourse->grade);
         if ($this->_isElective)
        $q->whereIn('a.student_sn',$studentArr);
        else
        $q->andWhere('b.class_sn=?', $this->_teacherCourse->class_sn);

        $res =$q->fetchArray();
        $arr = array();
        foreach($res as $row)
        $arr[$row['student_sn']] = $row;

        return $arr;
    }



    /**
     * 評語類別
     * @return array
     */
    public function getCommentKind()
    {

        $res = Doctrine_Query::create()
        ->from('Score_Model_CommentKind')
        ->where('teacher_sn=0') //OR teacher_sn=?',$this->_teacherSn)
        ->orderBy('teacher_sn DESC, sn')
        ->fetchArray();
        $arr = array();
        foreach($res as $row)
        $arr[$row['sn']] = $row['name'];
        return $arr;
    }

    /**
     * 評語等級
     * @return  array
     */
    public function getCommentLevel()
    {
        // 取預設等級及教師自訂等級
        $q = Doctrine_Query::create()
        ->from('Score_Model_CommentLevel')
        ->where('teacher_sn=0 ') //OR teacher_sn=?', $this->_teacherSn)
         ->orderBy('teacher_sn DESC, sn');
        $res =$q->fetchArray();
        $arr = array();
        foreach($res as $row)
        $arr[$row['sn']] = $row['name'];

        return $arr;
    }

}